<!--
 * @Author: WLang
 * @LastEditors: WLang
 * @Description: 
 * @Date: 2023-07-02 15:19:40
 * @LastEditTime: 2023-07-18 21:58:13
 * @FilePath: \myblog\src\views\ArticleView.vue
-->
<template>
  <div v-if="article.id">
    <BaseArtcileContent :article="article" :id="article.id"/>
    <CommentTextArea :aid="article.id"/>
    <CommentList :comments="article.comments"/>
  </div>
</template>

<script>
import BaseArtcileContent from '@/components/base/BaseArticleContent.vue'
import CommentTextArea from '@/components/comment/CommentTextArea.vue'
import CommentList from '@/components/comment/CommentList.vue'
import { createNamespacedHelpers } from 'vuex'
const {mapGetters, mapActions} = createNamespacedHelpers('like');
export default {
  components:{
    BaseArtcileContent,
    CommentTextArea,
    CommentList
  },
  provide() {
    return {
      getArticleById: this.getArticleById
    }
  },
  data(){
    return {
      id: '',
      article: {}
    }
  },
created(){
  this.id = this.$route.params.id;
  this.getArticleById();
},
mounted(){},
watch:{},
computed:{
},
methods:{
  ...mapActions(['pushLike', 'sendLikes']),
  async getArticleById() {
    try{
      this.article = await this.$api({type: 'getArticleById', data: {id: this.id}});
      let likeUsers = this.article?.like_users || []
      let uid = this.$store.getters.userInfo?._id
      if (likeUsers.includes(uid))
      {
        this.pushLike({aid: this.id})
      }
    }
    catch(err)
    {
      this.$notify.success({
      title: '获取失败',
      message: err.message
    })
    }
  }
},
beforeDestroy() {
}
}
</script>
<style  scoped>
</style>